package com.td.teach;

import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;

import com.td.teach.activity.BaseActivity;
import com.td.teach.activity.Page1Activity;
import com.td.teach.activity.Page2Activity;
import com.td.teach.activity.Page3Activity;
import com.td.teach.activity.Page4Activity;
import com.td.teach.activity.Page5Activity;
import com.td.teach.activity.Page6Activity;
import com.td.teach.activity.Page7Activity;

import java.util.ArrayList;
import java.util.List;

public class ContentActivity extends BaseActivity {


    private List<View> mViews = new ArrayList<>();

    private ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_content);


        viewPager = (ViewPager) findViewById(R.id.vp_main);

        initData();

        PagerAdapter adapter = new PagerAdapter() {
            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                container.addView(mViews.get(position));

                return mViews.get(position);
            }

            @Override
            public void destroyItem(ViewGroup container, int position, Object object) {
                container.removeView(mViews.get(position));
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }

            @Override
            public int getCount() {
                return mViews.size();
            }
        };

        viewPager.setAdapter(adapter);

//        viewPager.setPageTransformer(true, new CustomTransformer());

        viewPager.setOffscreenPageLimit(7);
        viewPager.setCurrentItem(3);

    }


    private void initData() {

        View view1 = LayoutInflater.from(this).inflate(R.layout.activity_01, null);
        View view2 = LayoutInflater.from(this).inflate(R.layout.activity_02, null);
        View view3 = LayoutInflater.from(this).inflate(R.layout.activity_03, null);
        View view4 = LayoutInflater.from(this).inflate(R.layout.activity_04, null);
        View view5 = LayoutInflater.from(this).inflate(R.layout.activity_05, null);
        View view6 = LayoutInflater.from(this).inflate(R.layout.activity_06, null);
        View view7 = LayoutInflater.from(this).inflate(R.layout.activity_07, null);


        mViews.add(view1);
        mViews.add(view2);
        mViews.add(view3);
        mViews.add(view4);
        mViews.add(view5);
        mViews.add(view6);
        mViews.add(view7);

    }

}
